﻿$(function (e) {
    var reentrance = false;
    $('[itemId=personCheckBox]').change(onPersonChecked);

    function onPersonChecked() {
        if (reentrance) return false;
        reentrance = true;
        var data = {};
        data.id = $(this).attr('name');
        data.personId = $(this).attr('personId');
        data.value = $(this).is(':checked');

        $.ajax({
            url: $(this).data('url'),
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify(data),
        }).done(function (args) {
            console.log(args);
            reentrance = false;
        });

        return false; // supposed to fix double events; calls stopPropagation and preventDefault
    };

    $('[itemId="isRandomOrderCheckBox"]').change(onIsRandomOrderChecked);
    function onIsRandomOrderChecked() {
        if (reentrance) return false;
        reentrance = true;
        var data = {};
        data.value = $(this).is(':checked');

        $.ajax({
            url: $(this).data('url'),
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify(data),
        }).done(function (args) {
            console.log(args);
            reentrance = false;
        });

        return false; // supposed to fix double events; calls stopPropagation and preventDefault
    };

});

